package com.example.swd1.gudong.main.sport.normalsport;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.swd1.gudong.R;


//==================================================================================================================
//   Author :  Shile Wu
//   Date  :  16-9-5
//   Role :    None
//   Reference documents : None
//==================================================================================================================
public class SportRecordGridViewAdapter extends BaseAdapter {
    private Context context;
     private String[] text = new String[]{"距离","时长","配速","平均配速","时速","平均时速","最大速度","卡路里","累计海拔上升","海拔","海拔上升","心率"};

    private int[] unCheckImg = new int[]{R.drawable.ic_sport_record_dis_normal, R.drawable.ic_sport_record_time_normal, R.drawable.ic_sport_record_inpace_normal,
            R.drawable.ic_sport_record_pace_normal, R.drawable.ic_sport_record_speed_normal, R.drawable.ic_sport_record_averagepace_normal,
            R.drawable.ic_sport_record_maxspeed_normal, R.drawable.ic_sport_record_cal_normal, R.drawable.ic_sport_record_climb_normal,
            R.drawable.ic_sport_record_altitude_normal, R.drawable.ic_sport_record_upheight_normal, R.drawable.ic_sport_record_heart_rate_normal};
    private int[] checkImg = new int[]{R.drawable.ic_sport_record_dis_selected, R.drawable.ic_sport_record_time_selected, R.drawable.ic_sport_record_inpace_selected,
            R.drawable.ic_sport_record_pace_selected, R.drawable.ic_sport_record_speed_selected, R.drawable.ic_sport_record_averagepace_selected,
            R.drawable.ic_sport_record_maxspeed_selected, R.drawable.ic_sport_record_cal_selected, R.drawable.ic_sport_record_climb_selected,
            R.drawable.ic_sport_record_altitude_selected, R.drawable.ic_sport_record_upheight_selected, R.drawable.ic_sport_record_heart_rate_selected};


    private int checkPosition = 5;

    public SportRecordGridViewAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return text.length;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        viewHolder holder;
        if (convertView == null) {
            holder = new viewHolder();
            convertView = View.inflate(context, R.layout.item_sport_value_type_grid_view, null);
            holder.recordImg = (ImageView) convertView.findViewById(R.id.item_record_img);
            holder.recordText = (TextView) convertView.findViewById(R.id.item_record_text);
            convertView.setTag(holder);
        } else {
            holder = (viewHolder) convertView.getTag();
        }
        if (checkPosition == position) {
            holder.recordImg.setImageResource(checkImg[position]);
        } else {
            holder.recordImg.setImageResource(unCheckImg[position]);
        }

        holder.recordText.setText(text[position]);
        return convertView;
    }

    public void setCheckPosition(int position) {
        this.checkPosition = position;
    }

    private class viewHolder {
        ImageView recordImg;
        TextView recordText;
    }
}
